<!DOCTYPE html>
<head>
    <#assign dicSelect = JspTaglibs["http://www.casic304.cn/dicSelect"]/>
    <#assign secSelect = JspTaglibs["http://www.casic304.cn/secSelect"] />
    <#assign fillDept=JspTaglibs["http://www.casic304.cn/fillDept"] />
    <#assign DutyDept = JspTaglibs["http://www.casic304.cn/DutyDept"]/>
    <meta charset="utf-8">
    <title>综合质量管理日常检查基本信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/qbdmsStatic/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/qbdmsStatic/style/qbdms.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
</head>
<body class="listBody">
<div class="qbdms-bodyDiv">
    <div class="layui-table-view-body qbdms-add-view-body">
        <form class="formPreview layui-form" requrl="${ctx}/qbdms/wQbdDailyInspect/get" lay-filter="wQbdDailyInspectDataForm" id="wQbdDailyInspectDataForm">
            <div class="layui-hide">
                <input type="text" name="id" placeholder="请输入" autocomplete="off" class="layui-input " maxlength="50">
                <input name="filldeptid" value="${filldeptid}" style="display: none"/>
                <input name="filldept" value="${filldept}" style="display: none"/>
                <input name="fillmanaccount" value="${fillmanaccount}" style="display: none"/>
                <input name="fillman" value="${fillman}" style="display: none"/>
                <input name="filldate" value="${filldate}" style="display: none"/>
                <input name="flowStatus" value="${flowStatus}" style="display: none"/>
                <input name="attachment_url" value="${attachment_url}" style="display: none"/>
            </div>
            <div class="qbdms-formTitle">日常检查信息 <i class="qbdms-returnOn closeWindow" id="back">返回</i></div>
            <div class="qbdms-formBody">
                <@fillDept.dept id="tbxx"/>
                <div class="layui-row">
                    <div class="qbdms-oneForm">
                        <label class="layui-form-label qbdms-label" title="密级">密级<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                            <@secSelect.sec_select data_src=1 required=true name="secret" id="secret"/>
                        </div>
                    </div>
                    <div class="qbdms-oneForm">
                        <label class="layui-form-label qbdms-label" title="责任单位"><span style="color: red;">*</span>责任单位</label>
                        <div class="layui-input-block qbdms-input">
                            <select id="dutydept" name="dutydept" autocomplete="off"
                                    class="layui-input" lay-filter="dutydept"
                                    fieldname="dutydept" lay-verify="required"
                                    lay-reqtext="责任单位是必填项">
                            </select>
                        </div>
                        <input type="hidden" name="dutydeptname" id="dutydeptname">
                    </div>
                    <div class="qbdms-textarea">
                        <label class="layui-form-label qbdms-label">问题内容<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                            <textarea id="content" rows="2" class="layui-textarea" placeholder="请输入" name="content" maxlength="160" lay-verify="required" lay-reqtext="问题内容是必填项"></textarea>
                        </div>
                    </div>

                    <div class="qbdms-oneForm">
                        <label class="layui-form-label qbdms-label" title="计划完成时间">计划完成时间<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                            <input type="text" placeholder="请选择" autocomplete="off" readonly class="layui-input dateTimeFiled input-right time-init" id="finishdate" name="finishdate" format="yyyy-MM-dd" datetype="date" lay-verify="required" lay-reqtext="计划完成时间是必填项">
                        </div>
                    </div>
                    <div class="qbdms-oneForm">
                        <label class="layui-form-label qbdms-label" title="检查日期">检查日期<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                            <input type="text" placeholder="请选择" autocomplete="off" readonly class="layui-input dateTimeFiled input-right time-init" id="inspectdate" name="inspectdate" format="yyyy-MM-dd" datetype="date" lay-verify="required" lay-reqtext="检查日期是必填项">
                        </div>
                    </div>
                    <#if isInclude=='true'>
                    <#include "/wQbdDailyInspect/two.html">
                </#if>
                </div>
            </div>
            <div class="layui-form-item btnformItem">
                <p>
                    <span id="hideAndShow" style="display: none;">
                        <a lay-submit lay-filter="wQbdDailyInspect" class="layui-btn btn-n privateSubmit qbdms-oneBtn" requrl="${ctx}/qbdms/wQbdDailyInspect/save" id="urlFormSave">保存</a>
                        <a lay-filter="wProblemresetMsg" id="run" class="layui-btn btn-n qbdms-oneBtn">启动</a>
                        <button type="reset" id="closeWindow" style="margin-left: 10px;" class="layui-btn layui-btn-sm btn-save qbdms-oneBtnLine">取消</button>
                    </span>
                </p>
            </div>
        </form>
    </div>
</div>
<script src="${ctx}/public/component.js" type="text/javascript"></script>
<script src="${ctx}/json/comboselect.js" type="text/javascript"></script>
<script src="${ctx}/qbdmsStatic/public/configFile.js"></script>
<script src="${ctx}/layui/layui.js"></script>
<script>
    var vaildFlag ;
    var runFlag=false;
    var flowStatus="${flowStatus}";
    layui.config({
        base: serverPath.qbdmsPath + staticPath.qbdmsPath //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'setter', 'layer', 'propsHandle', 'upload', 'common', 'laydate', 'jquery', 'publicMethods', 'qbdmsForm','form'], function () {

        // -----常量声明----------
        var $ = layui.jquery,
            laydate = layui.laydate,
            setter = layui.setter,  // 配置信息
            layer = layui.layer,
            common = layui.common,
            propsHandle = layui.propsHandle,
            upload = layui.upload,
            publicMethods = layui.publicMethods,
            formId = '${formDefId}' || '',
            defProps = {
                //viewMould: 'form/formDef/view/formDesign/moulds/', // 组件模块 存放文件 *****
                viewMould: 'moulds/', // 组件模块 存放文件 *****
                formAreaInfo: '.formPreview',
                formAreaInfo: 'html',
                temDate: '.temDate',
                uploadFileBtn: '.uploadFileBtn',
                uploadImgBtn: '.uploadImgBtn',
                richTextArea: '.richTextArea',
                selectInput: '.selectInput',
                radioOptionCont: '.radioOptionCont',
                dataLexiTree: '.dataLexiTree',
                selectorBtn: '.selectorBtn'
            },
            temQuery = new propsHandle(),  // 实例化模板功能部分
            form = layui.qbdmsForm;
            forms = layui.form;
        // 初始化模板功能
        temQuery.initTem({
            selectorBtn: defProps.selectorBtn,
            selectorTemPath: setter.views + defProps.viewMould
        });

        if("${isInclude}"=="true") {
            $(".subContTem").hide();
            $(".qbdms-SubTableTitle").hide();
            $(".qbdms-tableDiv").hide();
            $("#secret").attr("disabled", true);
            $("#dutydept").attr("disabled", true);
            $("#content").attr("disabled", true);
            $("#finishdate").attr("disabled", true);
            $("#inspectdate").attr("disabled", true);
        }
        var researchRoomList = eval('${researchRoomList}'); //问题责任单位
        var researchRoom = function(optionObj, item){
            optionObj.text = item.orgName;
            optionObj.value = item.code;
        };
        common.initDicData("dutydept", researchRoomList, "", researchRoom);
        var dateTimeFiledLen = $(".dateTimeFiled");
        // $()
        if("${isInclude}"=="true"){
            for (var i = 0; i < dateTimeFiledLen.length; i++) {
                laydate.render({
                    elem: dateTimeFiledLen[i] //指定元素
                    , type: 'date'
                    , trigger: 'click'
                });
            }

        }else{
            for (var i = 0; i < dateTimeFiledLen.length; i++) {
                laydate.render({
                    elem: dateTimeFiledLen[i] //指定元素
                    , type: 'date'
                    , trigger: 'click'
                });
            }
        }



        //- 添加表单验证规则 开始 ---------------------------------------------------------------------
        form.verify({
            length100:[/^.{0,100}$/,'输入字符数不能超过100'],
            length2000:[/^.{0,2000}$/,'输入字符数不能超过2000'],
            fileRequired: function (value,item) {
                value = $(item).siblings(".uploadInput").val()
                if(!new RegExp(/[\S]+/).test(value)){
                    return common.verifyTitleAdd(item) +"没有上传对应附件"
                }
            },
            money: function (value,item) {
                if (value && !new RegExp(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/).test(value)) {
                    return common.verifyTitleAdd(item) +'请输入数字且小数最多两位';
                }
            },
            integer: function (value,item) {
                if (value && !new RegExp(/^[+]{0,1}(\d+)$/).test(value)) {
                    return common.verifyTitleAdd(item) + '请输入正整数';
                }
            }
        });
        //- 添加表单验证规则 结束 ---------------------------------------------------------------------

        form.on('select(xh)', function (data) {
            $("input[name='fModelname']").val(data.elem[data.elem.selectedIndex].getAttribute("xhmc"));
        });

        vaildFlag = false;
        $("#urlFormSave").click(function () {
            vaildFlag=form.VerifyForm("wQbdDailyInspectDataForm");
            //- 附件密级不能高于表单密级 开始 ------------------------------------------------------
            var selectMaxVal = 0;
            var formSecretVal = $("[name='secret']").val();
            $(".fileSecLevel select").each(function () {
                selectMaxVal = selectMaxVal >= $(this).val() ? selectMaxVal : $(this).val();
            });

            if (selectMaxVal > formSecretVal) {
                layer.msg('附件密级不能高于表单密级。', {icon: 5});
                vaildFlag = false;
                return false;
            }
            //- 附件密级不能高于表单密级 结束 ------------------------------------------------------
        });

        //关闭当前页面
        $("#closeWindow,.closeWindow").click(function () {
            var mdb = "${db}";
            if(null != mdb && 'db' === mdb && undefined != mdb){
                window.location.href = serverPath.qbdmsPath + '/qbdms/wQbdDailyInspect/view/list';
                return;
            }
            window.location.href = serverPath.qbdmsPath + '/qbdms/wQbdDailyInspect/view/list';
        });

        if(flowStatus == null || flowStatus == 0|| flowStatus==99){
            $("#hideAndShow").show();
        }else{
            $("#back").hide();
        }
        if(flowStatus==99){
            $("#run").hide();
        }
        form.on('select(dutydept)', function (data) {
         console.log(data.elem[data.elem.selectedIndex].text);
         $("#dutydeptname").val(data.elem[data.elem.selectedIndex].text);
        });
        var index = parent.layer.getFrameIndex(window.name);
        common.updateForm({
            name: 'wQbdDailyInspectDataForm',
            idValue: "${id}",
            primary: "id",
            beforeSubmitFun: function (data) {
                if("${isInclude}"=="true") {
                    var rectification = $("[name='rectification']").val();
                    var actualfinishdate = $("[name='actualfinishdate']").val();
                    var attachment_url = $("[name='attachment_url']").val();
                    var fmtDate = new Date(actualfinishdate.replace(/\-/g, "\/"));

                    //- 附件密级不能高于表单密级 开始 ------------------------------------------------------
                    var selectMaxVal = 0;
                    var formSecretVal = $("[name='secret']").val();
                    $(".fileSecLevel select").each(function () {
                        selectMaxVal = selectMaxVal >= $(this).val() ? selectMaxVal : $(this).val();
                    });

                    if (selectMaxVal > formSecretVal) {
                        layer.msg('附件密级不能高于表单密级。', {icon: 5});
                        vaildFlag = false;
                        return false;
                    }
                    //- 附件密级不能高于表单密级 结束 ------------------------------------------------------
                    $(".uploadFileList").each(function (i, v) {
                        common.constructFileStr(v)
                    });
                    var files = [];
                    //整理上传附件的隐藏域，将提交的字符串转为json对象
                    $(".uploadInput").each(function () {
                        var uploadName = $(this).attr("name");
                        if (!$(this).val()) {
                            return;
                        }
                        data.field[uploadName] = eval($(this).val());
                        files = files.concat(eval($(this).val()));
                    });
                    // 控制文件密级
                    return common.setFileLevel(files);
                }
            },
            getCallback: function (data) {
                $("#tbxx").html("<span class='qbdms-TBinformation'>填报信息:</span><span class='qbdms-TBinformationText'>【" + data.data.filldept + " | " + data.data.fillman + " | " + data.data.filldate + "】</span><br />");
                if("${isInclude}"=="true") {
                    $('.uploadFileList').each(function () {
                        var fileUploadName = $(this).attr("fileUploadName");
                        var jsonFile = data.data[fileUploadName];
                        var files = eval(jsonFile);

                        if (files) {
                            for (var i = 0; i < files.length; i++) {
                                var fileLevel = files[i].fileLevel;
                                var fileLevelText = files[i].fileLevelText;
                                var fileSec = '<div class="fileSecLevel fileSecXg layui-input-inline">' + '<@secSelect.sec_select data_src=1 hasBlank=false/>' + "</div>";
                                var newStr = '<span class="file-id" style="margin-right: 20px;" fileId=' + files[i].fileId + ' fileLevelText="' + fileLevelText + '">' + fileSec + '<span class="file-name" title="点击下载文件" onclick="downFile(this)"><i class="iconfont" style="margin-right: 5px"></i>' + files[i].fileName + '</span></span>';
                                $(this).html(newStr);
                                $(this).find("select:last").val(fileLevel);
                                $(this).find("select:last").attr("disabled", "disabled");
                            }
                        } else {
                            $(this).html("<span style='color: #c0c4cc'>未上传</span>");
                        }
                    });
                }
                form.render();
            },
            updateCallback: function (data) {
                if((flowStatus==0||flowStatus==""||null==flowStatus)&&runFlag==true){
                    run(data.data.id);
                }
                if (publicMethods._filterRecord(data)) {
                    if ($(".privateSubmit")) {
                        $(".privateSubmit").attr("disabled", false).css("pointer-events", "auto");
                    }
                    if((flowStatus=="0" || flowStatus==null||flowStatus==""||flowStatus=="99")&&runFlag==false) {
                        layer.alert(publicMethods.confirmStyle(data.msg), {
                            title: false,
                            skin: 'confirm-class'
                        }, function (index) {
                            layer.close(index);
                            window.location.href = serverPath.qbdmsPath + '/qbdms/wQbdDailyInspect/view/list';
                        });
                    }
                } else {
                    layer.alert(publicMethods.confirmStyle(data.msg),{title: false,skin: 'confirm-class'});
                }
                runFlag=false;
                return false;
            }

        });

        window.downFile = function (obj) {
            var fileId = $(obj).parents("span").attr("fileId");
            window.location.href = serverPath.qbdmsPath + setter.extendLinkPath + "attachFile/download?fileId=" + fileId;
        }

        $("#run").click(function () {
            var flag=form.VerifyForm("wQbdDailyInspectDataForm");
            if(flag==false){
                return false;
            }
            runFlag=true;
            $("#urlFormSave").click();
        })
        function run(id) {
            var id = id;
            var content = $("input[name='content']").val();
            var dutydept = $("input[name='dutydept']").val();
            var inspectdate = $("input[name='inspectdate']").val();
            var finishdate = $("input[name='finishdate']").val();
            var actualfinishdate = $("input[name='actualfinishdate']").val();
            var rectification = $("input[name='rectification']").val();
            var attachmentUrl = $("input[name='attachmentUrl']").val();
            var fillman = $("input[name='fillman']").val();
            var filldept = $("input[name='filldept']").val();
            var filldate = $("input[name='filldate']").val();
            var tenantId = $("input[name='tenantId']").val();
            var createBy = $("input[name='createBy']").val();
            var createTime = $("input[name='createTime']").val();
            var updateBy = $("input[name='updateBy']").val();
            var updateTime = $("input[name='updateTime']").val();
            var secret = $("input[name='secret']").val();
            var fillmanaccount = $("input[name='fillmanaccount']").val();
            var filldeptid = $("input[name='filldeptid']").val();
            var filldepthospitalid = $("input[name='filldepthospitalid']").val();
            var filldepthospital = $("input[name='filldepthospital']").val();
            var reportStatus = $("input[name='reportStatus']").val();
            var reportReason = $("input[name='reportReason']").val();
            var reportStatusTemp = $("input[name='reportStatusTemp']").val();
            var returnmsg = $("input[name='returnmsg']").val();
            var reportDate = $("input[name='reportDate']").val();
            var belongdeptname = $("input[name='belongdeptname']").val();
            var dutydeptname = $("input[name='dutydeptname']").val();
            var flowStatus = $("input[name='flowStatus']").val();
            var nowData = {"id": id,"content": content,"dutydept": dutydept,"inspectdate": inspectdate,"finishdate": finishdate,"actualfinishdate": actualfinishdate,"rectification": rectification,"attachmentUrl": attachmentUrl,"fillman": fillman,"filldept": filldept,"filldate": filldate,"tenantId": tenantId,"createBy": createBy,"createTime": createTime,"updateBy": updateBy,"updateTime": updateTime,"secret": secret,"fillmanaccount": fillmanaccount,"filldeptid": filldeptid,"filldepthospitalid": filldepthospitalid,"filldepthospital": filldepthospital,"reportStatus": reportStatus,"reportReason": reportReason,"reportStatusTemp": reportStatusTemp,"returnmsg": returnmsg,"reportDate": reportDate,"belongdeptname": belongdeptname,"dutydeptname": dutydeptname,"flowStatus": flowStatus};
            $.ajax({
                url:"${ctx}/qbdms/wQbdDailyInspect/run",
                type: "post",
                dataType: 'json',
                contentType : 'application/json',
                data: JSON.stringify(nowData),
                success : function (data) {
                    if (common.filterRecord(data)) {
                        layer.alert(publicMethods.confirmStyle(data.msg), {
                            title: false,
                            skin: 'confirm-class'
                        }, function (index) {
                            layer.close(index);
                            window.location.href = serverPath.qbdmsPath + '/qbdms/wQbdDailyInspect/view/list';
                        });
                    } else {
                        layer.alert(publicMethods.confirmStyle(data.msg), {
                            title: false,
                            skin: 'confirm-class'
                        }, function (index) {
                            layer.close(index);
                            window.location.href = serverPath.qbdmsPath + '/qbdms/wQbdDailyInspect/view/list';
                        });
                    }
                    return false;
                },
                error : function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert(publicMethods.confirmStyle("内容已保存，启动失败"), {
                        title: false,
                        skin: 'confirm-class'
                    }, function (index) {
                        layer.close(index);
                        window.location.href = serverPath.qbdmsPath + '/qbdms/wQbdDailyInspect/view/list';
                    });
                }
            })
        }

        publicMethods.bottomFixd()
        form.on('select', function (data) {
            publicMethods.bottomFixd()
        });
        form.render();
        var secSelect = '<@secSelect.sec_select data_src=1 hasBlank=false/>'
        common.uploadfun(".fileUpload", {
            acceptMime: 'application/pdf, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document',
            exts: "doc|docx|pdf",
            secSelect: secSelect,
            isSub: false,
            upLoadSize:102400,
            upLoadNumber: 1,
            isMultiFile: false
        });
    });


</script>
</body>
</html>